using System;
using System.ComponentModel;
using System.Windows.Forms;

using Pegasus.Windows.Forms;

namespace Pegasus.Sample.FormEx
{
	/// <summary>
	/// Sample form for using the FormEx class
	/// </summary>
	public partial class FormMain : Pegasus.Windows.Forms.FormEx
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="FormMain"/> class.
		/// </summary>
		public FormMain()
			// Give the name of the storage bag that will be used to hold the users settings.
			: base( "NameOfStoreage" )
		{
			InitializeComponent();

			// Load the value into the check state
			if( UserData.ContainsKey( "UserCheckBox" ) )
			{
				CheckUserSettings.Checked = (bool) UserData[ "UserCheckBox" ];
			}

			if( ApplicationData.ContainsKey( "AppCheckBox" ) )
			{
				CheckApplicaiton.Checked = (bool) ApplicationData[ "AppCheckBox" ];
			}
		}

		/// <summary>
		/// Raises the <see cref="E:Closing"/> event.
		/// </summary>
		/// <param name="args">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
		protected override void OnClosing( CancelEventArgs args )
		{
			base.OnClosing( args );

			// Save the data
			UserData[ "UserCheckBox" ] = CheckUserSettings.Checked;
			ApplicationData[ "AppCheckBox" ] = CheckApplicaiton.Checked;
		}
	}
}